package org.hk.controller;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/cc1")
public class TestS extends HttpServlet {
  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
      //允许跨域访问，通过response对象写回一些跨域访问的头信息
      response.setHeader("Access-Control-Allow-Origin","*");
      //允许请求的方法
      response.setHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE");
      PrintWriter out = response.getWriter();
      out.println("aaaaaaa33331");
      out.flush();
      out.close();
  }
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException{
        //允许跨域访问，通过response对象写回一些跨域访问的头信息
        response.setHeader("Access-Control-Allow-Origin","*");
        //允许请求的方法
        response.setHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE");
        PrintWriter out = response.getWriter();
        out.println("post");
        out.flush();
        out.close();
    }
    public void doPut(HttpServletRequest request, HttpServletResponse response) throws IOException{
        //允许跨域访问，通过response对象写回一些跨域访问的头信息
        response.setHeader("Access-Control-Allow-Origin","*");
        //允许请求的方法
        response.setHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE");
        PrintWriter out = response.getWriter();
        out.println("put");
        out.flush();
        out.close();
    }
    public void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException{
        //允许跨域访问，通过response对象写回一些跨域访问的头信息
        response.setHeader("Access-Control-Allow-Origin","*");
        //允许请求的方法
        response.setHeader("Access-Control-Allow-Methods","GET,POST,PUT,DELETE");
        PrintWriter out = response.getWriter();
        out.println("delete");
        out.flush();
        out.close();
    }
}
